package com.qzy.reggie.mapper;

import com.qzy.reggie.pojo.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    @Select("<script>select * from employee " +
            "<where> " +
            "<if test='name!=null'> name like '${name}%'</if>" +
            "</where>" +
            "</script>")
    List<Employee> selectList(String name);

//    @Select("select * from employee where username = #{username}")
//    Employee selectByUsername(String username);

    @Insert("insert into employee (name,username,password,phone,sex,id_number,create_time,update_time,create_user,update_user) values (#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    Integer insert(Employee employee);

//    @Select("select id,name,username,password,phone,sex,id_number idNumber from employee where id = #{id}")
//    Employee selectOne(Long id);

    @Select("<script>" +
            "select id,name,username,password,phone,sex,id_number idNumber,status " +
            "from employee " +
            "<where> " +
            "<if test='id != null and id != 0'> and id = #{id}</if>" +
            "<if test='username != null'> and username = #{username}</if>" +
            "</where>" +
            "</script>")
    Employee selectOne(Employee employee);

    @Update("<script>update employee <set> " +
            "<if test='name != null'>name=#{name},</if>" +
            "<if test='username != null'>username=#{username},</if>" +
            "<if test='phone != null'>phone=#{phone},</if>" +
            "<if test='sex != null'>sex=#{sex},</if>" +
            "<if test='idNumber != null'>id_number=#{idNumber}</if> " +
            "<if test='status != null'>status=#{status}</if> " +
            "</set> where id=#{id} </script>")
    Integer update(Employee employee);
}
